USE [master]
GO

/****** Object:  UserDefinedFunction [dbo].[GetVDBAHeader]    Script Date: 08/28/2014 13:58:47 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetVDBAHeader]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[GetVDBAHeader]
GO

USE [master]
GO

/****** Object:  UserDefinedFunction [dbo].[GetVDBAHeader]    Script Date: 08/28/2014 13:58:47 ******/
SET ANSI_NULLS OFF
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE FUNCTION [dbo].[GetVDBAHeader](@HeaderType VARCHAR(10))
RETURNS VARCHAR(300)
AS
BEGIN
	--Returns the top 2 header lines in the VDBA Report for 'LOGF','INFO'
	--Returns single Heartbeat header  for 'HTBT'
	--Input the type of header: 'LOGF','HTBT','INFO' Inputs are trimmed and changed to Upper Case.
	DECLARE
	@CompanyNm varchar(100),
	@dt varchar(30),
	@Mail_Id varchar(255),
	@Header varchar(300)

	Set @HeaderType = LTRIM(RTRIM(UPPER(@HeaderType)))

	SET @Mail_Id = master.dbo.GetMail()
	SET @CompanyNm = master.dbo.GetCompanyNm()
	SET @dt = CONVERT(varchar(30),GETDATE(),121)
	SET @dt = LEFT(@dt,LEN(@dt) - 4)
	SET @dt = RTRIM(LTRIM(@dt))
	--Header information--Version information
	
	SET @Header = 'HEADER '+@HeaderType +  '|' + rtrim(ltrim(@dt)) + '|' + rtrim(ltrim(@companynm)) + '|' + @@servername + '|'  + @@servicename + '|' + rtrim(ltrim(@mail_id)) + '|'
	IF @HeaderType != 'HTBT' SET @Header = @Header	+ CHAR(13)+CHAR(10)+'VERSION|'  +substring(@@version,charindex(' on',@@version) + 4,charindex(' (Build',@@version) - (charindex(' on',@@version) + 4))+'|'+replace(left(@@version,charindex('-',@@version) - 1),'  ',' ') +'|'+cast(serverproperty('productlevel') as varchar(20))+'|'
	RETURN(@Header)
END

GO






